﻿using System;
using Framework.Core.Cache;
using Framework.Remoting.Client;
using Framework.Remoting.Testing;
using Framework.Tests.Wcf.Client.ServiceDefinition;
using Xunit;

namespace Framework.Tests.Wcf.Client
{
    public class ServiceClientCacheFactoryTest
    {
        [Fact]
        public void Should_cache_result()
        {
            using (var integrationTest = new IntegrationTest<IContract, Contract>(x => new ServiceClientCacheFactory(new DictionaryStorage(10, new TimeSpan(1, 0, 0, 0, 0)), x)))
            {
                var expected = integrationTest.Query(x => x.Add(1, 2));
                integrationTest.SimulateCommunicationProblem();

                var actual = integrationTest.Query(x => x.Add(1, 2));

                Assert.Equal(expected, actual);
            }
        }
    }
}